import Vue from 'vue'
import Vuex from 'vuex'
import { delUserInfo, get, getUserInfo, set, setUserInfo, del } from '@/utils/localstorage'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token: get() || null,
    user: getUserInfo() || {}
  },
  mutations: {
    setToken (state, token) {
      set(token)
    },
    setUserInfo (state, user) {
      setUserInfo(user)
      state.user = JSON.parse(JSON.stringify(user))
    },
    delUserInfo (state) {
      delUserInfo()
    },
    del (state) {
      del()
    }
  },
  actions: {

  },
  modules: {
  },
  getters: {
    getToken (state) {
      return state.token
    },
    getUserInfo (state) {
      return state.user
    }
  }
})
